//
//  BaseSingleSureView.m
//  Shengzhuli
//
//  Created by FXGuo on 2018/2/8.
//  Copyright © 2018年 kamangkeji. All rights reserved.
//

#import "BaseSingleSureView.h"
#import "NSDate+Extension.h"

@interface BaseSingleSureView()
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UILabel *countLab;
@property (weak, nonatomic) IBOutlet UILabel *pCountLab;
@property (weak, nonatomic) IBOutlet UILabel *priceLab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomInsetCons;


@end

@implementation BaseSingleSureView

+ (BaseSingleSureView *)singleSureView
{
    BaseSingleSureView *view = [[NSBundle mainBundle]loadNibNamed:@"BaseSingleSureView" owner:nil options:nil].lastObject;
    return view;
}
- (void)setModel:(SpecialModel *)model
{
    _model = model;
    NSMutableString *str = [NSMutableString string];
    for (NSDate *date in model.timeArr) {
        [str appendString:[self transTime:date]];
        [str appendString:@"  "];
    }
    self.timeLab.text = str;
    self.countLab.text = [NSString stringWithFormat:@"(共%zd天)",model.timeArr.count];
    self.pCountLab.text = [NSString stringWithFormat:@"%zd",model.count];
    self.priceLab.text = [NSString stringWithFormat:@"%.0f",model.sumPrice];
}

- (void)animatedShow
{
    self.bottomInsetCons.constant = 0;
    [UIView animateWithDuration:0.4 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self animatedHidden];
}
- (void)animatedHidden
{
    self.bottomInsetCons.constant = -250;
    [UIView animateWithDuration:0.4 animations:^{
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (IBAction)hiddenClick:(UIButton *)btn
{
    [self animatedHidden];
}


- (IBAction)payClick:(UIButton *)btn
{
    if (self.payBlock) {
        self.payBlock();
    }
}

- (NSString *)transTime:(NSDate *)date
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"MM月dd日";
    return [formatter stringFromDate:date];
}


@end
